using System;
using MetaBuilders.Irc;
using Microsoft.VisualStudio.TestTools.UnitTesting;


namespace MetaBuilders.NeboTests
{

	[TestClass]
	public class MaskTests
	{

		[TestMethod]
		public void ParseMask()
		{
			String raw;
			User mask;

			raw = "foo!bar@zap.com";
			mask = new User();
			mask.Parse( raw );
			Assert.AreEqual( "foo", mask.Nick, "Nick" );
			Assert.AreEqual( "bar", mask.UserName, "User" );
			Assert.AreEqual( "zap.com", mask.HostName, "Host" );

			raw = "foo!*@*.edu";
			mask = new User();
			mask.Parse( raw );
			Assert.AreEqual( "foo", mask.Nick, "Nick" );
			Assert.AreEqual( "*", mask.UserName, "User" );
			Assert.AreEqual( "*.edu", mask.HostName, "Host" );

			raw = "foo";
			mask = new User();
			mask.Parse( raw );
			Assert.AreEqual( "foo", mask.Nick );
			Assert.AreEqual( "", mask.UserName );
			Assert.AreEqual( "", mask.HostName );

			raw = "@foo";
			mask = new User();
			mask.Parse( raw );
			Assert.AreEqual( "foo", mask.Nick );
			Assert.AreEqual( "", mask.UserName );
			Assert.AreEqual( "", mask.HostName );
		}

		[TestMethod]
		public void MatchMask()
		{
			Assert.IsTrue( new User( "foo!bar@zap.com" ).IsMatch( new User( "foo!*@*.com" ) ) );
			Assert.IsFalse( new User( "foo!bar@zap.com" ).IsMatch( new User( "foo!*@*.edu" ) ) );
		}

		[TestMethod]
		public void RoundTrip()
		{
			String raw = "foo!bar@zap.com";
			User m = new User( raw );
			String parsed = m.ToString();
			Assert.AreEqual( raw, parsed );

			raw = "foo!*@*.edu";
			m = new User( raw );
			parsed = m.ToString();
			Assert.AreEqual( raw, parsed );

			raw = "foo@bar.net";
			m = new User( raw );
			parsed = m.ToString();
			Assert.AreEqual( raw, parsed );

			raw = "foo";
			m = new User( raw );
			parsed = m.ToString();
			Assert.AreEqual( raw, parsed );
		}

	}
}
